package cn.bby.tools.service;

import cn.bby.tools.actions.GenTemplateAction;
import cn.bby.tools.actions.str.convert.IdentifyWord;
import cn.bby.tools.dialog.FieldCompareDialog;
import cn.bby.tools.dialog.GenCurlDialog;
import cn.bby.tools.dialog.GenEntityFieldDialog;
import cn.bby.tools.dialog.GenMockDataDialog;
import cn.bby.tools.dialog.ParseCsvDialog;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.ApplicationKt;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;

/**
 * @description: StateManagementService
 * @author: ben
 * @date: 2025/9/25 16:30
 * @version: 1.0
 */
@Service(Service.Level.APP)
@State(name = "StateManagement", storages = @Storage("StateManagement.xml"))
public final class StateManagementService implements PersistentStateComponent<StateManagementService.StateData> {
    private final StateData state = new StateData();

    public static StateManagementService getInstance() {
        return ApplicationKt.getApplication().getService(StateManagementService.class);
    }

    public static StateData getInstanceState() {
        StateData stateData = getInstance().getState();
        return stateData == null? new StateData(): stateData;
    }

    @Override
    public StateManagementService.StateData getState() {
        return state;
    }

    @Override
    public void loadState(@NotNull StateData state) {
        XmlSerializerUtil.copyBean(state, this.state);
    }

    public static class StateData {
        public GenTemplateAction.GenTemplateState genTemplateState = new GenTemplateAction.GenTemplateState();
        public IdentifyWord.IdentifyWordState identifyWordState = new IdentifyWord.IdentifyWordState();
        public GenEntityFieldDialog.GenEntityFieldState genEntityState = new GenEntityFieldDialog.GenEntityFieldState();
        public GenMockDataDialog.GenMockDataState genMockDataState = new GenMockDataDialog.GenMockDataState();
        public GenCurlDialog.GenCurlState genCurlState = new GenCurlDialog.GenCurlState();
        public FieldCompareDialog.FieldCompareState fieldCompareState = new FieldCompareDialog.FieldCompareState();
        public ParseCsvDialog.ParseCsvState parseCsvState = new ParseCsvDialog.ParseCsvState();
    }

}